//
//  JokeBean.swift
//  test-ios
//
//  Created by wyz5204 on 2023/4/4.
//

import Foundation
import GRDB

struct Joke{
    struct DB : DBEntity{
        let id : Int
        let reason: String?
        let errorCode: Int
        
        func didInsert(with rowID: Int64, for column: String?) {
            print("did Insert \(rowID) , column = \(column)")
        }
        
        static var databaseTableName: String = "joke_table"
        
        
        func encode(to container: inout PersistenceContainer) {
            container["id"] = id
            container["reason"] = reason
            container["errorCode"] = errorCode
        }
        
//        init(row: Row) {
//            print("create 1 " ,row)
//            id = row["id"]
//            reason = row["reason"]
//            errorCode = row["errorCode"]
//            print("create 2 " ,row)
//        }
    }
    
    struct Result : Codable{
        let data: [Datum]
    }
    
    struct Datum : Codable{
        let content, hashID: String?
        let unixtime: Int?
        let updatetime: String?
        
        enum CodingKeys: String, CodingKey {
            case content
            case hashID = "hashId"
            case unixtime, updatetime
        }
    }
}
